package com.ymatou.iapi.productquery.compare;

import com.ymttest.utils.FileUtil;
import com.ymttest.utils.YMTDateUtil;

public class LoggerHelper {
	public static String folderPath = "D:\\compare\\data\\productquery\\";
	public static String logPath = "log.txt";
	public static String diffPath = folderPath + "diff.txt";
	public static String errorPath = folderPath + "error.txt";
	public static String syclogPath = folderPath + "sycLog.txt";

	
	public static void setfolderPath(String newPath){
		folderPath =newPath;
		logPath = folderPath + "log.txt";
		diffPath = folderPath + "diff.txt";
		errorPath = folderPath + "error.txt";
		syclogPath = folderPath + "sycLog.txt";
	}
	
	
	
	
	public static boolean verifyIsNull(Object obj, String desc,boolean isWriteRet) {
		if (obj != null && obj != "null" && obj.toString().length() != 0) {
			writeResult(diffPath, desc,isWriteRet);
			return false;
		} else {
			writeResult(logPath, desc,isWriteRet);
			return true;
		}
	}

	public static boolean verifyNotNull(Object obj, String desc, boolean isWriteRet) {
		if (obj != null && obj != "null" && obj.toString().length() != 0) {
			writeResult(logPath, desc,isWriteRet);
			return true;
		} else {
			writeResult(diffPath, desc,isWriteRet);
			return false;
		}
	}

	public static boolean verifyEquals(Object expected, Object actual, String desc,boolean isWriteRet) {
		if (expected != null && actual != null) {
			if (expected.equals(actual)) {
				writeResult(logPath, desc,isWriteRet);
				return true;
			} else {
				writeResult(diffPath, desc,isWriteRet);
				return false;
			}
		} else if (expected == actual) {
			writeResult(logPath, desc,isWriteRet);
			return true;
		} else {
			writeResult(diffPath, desc,isWriteRet);
			return false;
			
		}
	}

	public static void failure(String desc,boolean isWriteRet){
		writeResult(errorPath, desc,isWriteRet);
	}
	
	
	
	
	public static void writeResult(String filePath, String desc,boolean isWriteRet) {
		if (isWriteRet){
			if (filePath == null || filePath.equals("")) {
				// no name or name empty, do nothing
			} else {
				FileUtil.writeAsLine( filePath, YMTDateUtil.getSysTime() + ","+desc);
		}
		}

	}
	
	
	

}
